import actionType from '../actions/actiontype'


const adminIfos=JSON.parse(window.localStorage.getItem('adminInfo'))||JSON.parse(window.sessionStorage.getItem('adminInfo'))
const initstate={
  ...adminIfos,
   isLogin:Boolean(window.localStorage.getItem('authToken'))||Boolean(window.sessionStorage.getItem('authToken')),
   isLading:false


}


export default (state=initstate,action)=>{
  
    
    switch (action.type) {
       case actionType.STARTLOGIN:
            return {
                ...state,
                isLading:true
            }
        case actionType.LOGINSUCCESS:
          
                return {
                    ...state,
                    ...action.payload.ueseinfo,
                    isLading:false,
                    isLogin:true
                }
         case actionType.LOGINFAILED: 
         return {
            ...state,
            isLogin:false
         }      
        default:
          return state
    }
}
